package com.zyk.leetcode;

/**
 * @author zhangsan
 * @date 2021/5/11 10:55
 */
public class C914 {

    // 将牌分成X组(X>1), 且每组牌的张数相同, 每组内牌的值相同
    public boolean hasGroupsSizeX(int[] deck) {
        int[] count = new int[10000];
        for (int c: deck) {
            count[c]++;
        }

        int g = -1;
        for (int i = 0; i < 10000; ++i) {
            if (count[i] > 0) {
                if (g == -1) {
                    g = count[i];
                } else {
                    g = gcd(g, count[i]);
                }
            }
        }
        return g >= 2;
    }

    // 最小公倍数
    public int gcd(int x, int y) {
        return x == 0 ? y : gcd(y % x, x);
    }

}
